package com.slimbloody.controller;

import com.google.protobuf.ProtocolStringList;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import protobuf.ReflectPb;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/PbReflect")
public class PbReflectController {

  @PostMapping("re")
  public void re() {
  }

  @PostMapping("map")
  public void map() {
    int loop = 3;
    int intVal = 1;
    String strVal = "a";
    float floatVal = 1.0f;

    ReflectPb.SourceA.Builder aBuilder = ReflectPb.SourceA.newBuilder();

    aBuilder.setA(intVal);
    aBuilder.setB(strVal);
    aBuilder.setC(floatVal);
    ReflectPb.SourceA sourceA = aBuilder.build();

    ReflectPb.SourceB.Builder bBuilder = ReflectPb.SourceB.newBuilder();
    for (int i = 0; i < loop; i++) {
      bBuilder.addD(intVal);
      bBuilder.addE(strVal);
      bBuilder.addF(floatVal);
    }

    ReflectPb.SourceB sourceB = bBuilder.build();
    List<Integer> dList = sourceB.getDList();
    ProtocolStringList eList = sourceB.getEList();
    List<Float> fList = sourceB.getFList();

    ReflectPb.Target.Builder tBuilder = ReflectPb.Target.newBuilder();
    tBuilder.setA(sourceA.getA());
    tBuilder.setB(sourceA.getB());
    tBuilder.setC(sourceA.getC());
    tBuilder.addAllD(sourceB.getDList());
    tBuilder.addAllE(sourceB.getEList());
    tBuilder.addAllF(sourceB.getFList());
    ReflectPb.Target target = tBuilder.build();
    ReflectPb.Target target1 = target.toBuilder().addD(2).build();
    System.out.println();
  }

  public static void main(String[] args) {
    PbReflectController controller = new PbReflectController();
    controller.map();
  }
}
